package com.fancon.rage.comic.vn.gui;

import com.fancon.rage.comic.vn.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class TopControlView extends LinearLayout {
	private Context mContext;
	public static final int VN_MODE = 0x1;
	public static final int EN_MODE = 0x2;
	protected OnClickListener mOnClickListener;
	protected static View currentSelected;
	protected Button mBtnVn;
	protected Button mBtnEn;
	private int currentMode = 0x1;

	public TopControlView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		mContext = context;
		LayoutInflater layoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = layoutInflater.inflate(R.layout.top_control_view, this);
		mBtnVn = (Button) view.findViewById(R.id.btn_vn);
		mBtnEn = (Button) view.findViewById(R.id.btn_en);

		mOnClickListener = new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// resetSelected();
				if (v == mBtnVn) {
					mBtnEn.setBackgroundResource(R.drawable.btn_top_en);
					mBtnVn.setBackgroundResource(R.drawable.btn_top_vn_active);
					mBtnEn.setTextColor(mContext.getResources().getColor(
							R.color.white));
					mBtnVn.setTextColor(mContext.getResources().getColor(
							R.color.orange));
					currentSelected = mBtnVn;
					currentMode = VN_MODE;
					doGrid();
				} else if (v == mBtnEn) {
					mBtnVn.setBackgroundResource(R.drawable.btn_top_vn);
					mBtnEn.setBackgroundResource(R.drawable.btn_top_en_active);
					mBtnVn.setTextColor(mContext.getResources().getColor(
							R.color.white));
					mBtnEn.setTextColor(mContext.getResources().getColor(
							R.color.orange));
					currentSelected = mBtnEn;
					currentMode = EN_MODE;
					doList();
				}
			}

		};
		mBtnVn.setOnClickListener(mOnClickListener);
		mBtnEn.setOnClickListener(mOnClickListener);
	}

	private void resetSelected() {
		mBtnVn.setBackgroundResource(R.drawable.btn_top_vn);
		mBtnEn.setBackgroundResource(R.drawable.btn_top_en);
	}

	public void doGrid() {
		// TODO Auto-generated method stub
		if (mContext instanceof IRageTopControl) {
			((IRageTopControl) mContext).doVn();
		}
	}

	public void doList() {
		// TODO Auto-generated method stub
		if (mContext instanceof IRageTopControl) {
			((IRageTopControl) mContext).doEn();
		}
	}

	public int getCurrentMode() {
		return currentMode;
	}

	public void setCurrentMode(int currentMode) {
		this.currentMode = currentMode;
	}
}
